August 30, 2020
Here we go with next…Working with the mtcars dataset which we loaded before. Check the below screenshot for reference.
dst_n1 = dst.loc[(dst[‘cyl’] == 6) | (dst[‘mpg’] == 21)] Here we are selecting rows which has cyl = 6, and mpg = 21.
import numpy as np
dst[‘NwVar’] = np.log2(dst[‘cyl’])
New Variable named ‘NwVar’ has been created in last column.
import pandas as pd
df1 = pd.DataFrame({‘a’ : [1,2,3,4], ‘b’ : [4,5,6,7]})
df2 = pd.DataFrame({‘a’ : [7,8,9,2], ‘b’ : [3,7,8,9]})
df3 = df1.append(df2)
df3 = pd.concat([df1.reset_index(drop=True), df2], axis=1)
dt = mtcars dt[‘cyl’] = dst[‘cyl’].astype(object)
check the below screenshots where variable ‘cyl’ is mentioned as ‘Int’ and after converting it shows as ‘Object’.
dst = dst.astype(object)
dst[‘mpgcat’] = np.where(dst[‘mpg’] > 20, ‘Low’, 0)
dst = dst.sort_values(‘cyl’, ascending = True)
dst = dst.sort_values(‘cyl’, ascending = False)
Will end up here and see the next in next.